<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="1000" destroy-on-close @closed="$emit('closed')" align-center :close-on-click-modal="false" draggable overflow>
		<el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="90" label-position="right">
            <el-form-item label="Time" prop="time">
                <el-date-picker v-model="form.time" type="datetime" placeholder="请选择日期" :value-format="'YYYY-MM-DD HH:mm'" style="width:100%" />
            </el-form-item>
            <el-form-item label="Amount" prop="amount">
                <el-input v-model="form.amount" placeholder="请输入本次提货数量" clearable></el-input>
            </el-form-item>
            <el-form-item label="Driver" prop="driver">
                <el-input v-model="form.driver" placeholder="请输入司机" clearable></el-input>
            </el-form-item>
            <el-form-item label="Operater" prop="operater">
                <el-input v-model="form.operater" placeholder="请输入操作人" clearable></el-input>
            </el-form-item>
            <el-form-item label="Remark" prop="remark">
                <el-input v-model="form.remark" placeholder="请输入备注" clearable></el-input>
            </el-form-item>
            <!-- <sc-form-table ref="table" class="formtable" v-model="form.data" placeholder="暂无数据" :addTemplate="addTemplate" height="400" show-summary>
                <el-table-column label="Time" align="center">
                    <template #default="scope">
                        <el-date-picker v-model="scope.row.time" type="datetime" placeholder="请选择日期" :value-format="'YYYY-MM-DD HH:mm'" style="width:100%" />
                    </template>
                </el-table-column>
                <el-table-column label="Amount" align="center" prop="amount">
                    <template #default="scope">
                        <el-input v-model="scope.row.amount" placeholder="请输入手续费" clearable></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="Driver" align="center">
                    <template #default="scope">
                        <el-input v-model="scope.row.driver" placeholder="请输入司机" clearable></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="Operater" align="center">
                    <template #default="scope">
                        <el-input v-model="scope.row.operater" placeholder="请输入操作人" clearable></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="Remark" align="center">
                    <template #default="scope">
                        <el-input v-model="scope.row.remark" placeholder="请输入备注" clearable></el-input>
                    </template>
                </el-table-column>
            </sc-form-table> -->
		</el-form>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			dialog: {
				client: false
			},
			mode: "add",
			titleMap: {
				add: '设置状态',
				edit: '提货',
			},
			visible: false,
			isSaveing: false,
			//表单数据
			form: {
                id: "",
                contract_id: "",
                time: this.moment().format("YYYY-MM-DD HH:mm"),
                amount: "",
                driver: "",
                operater: this.$TOOL.data.get("USER_INFO").name,
                remark: "",
				// data: [],
			},
            addTemplate: {},
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
                    var res = await this.$API.business.pick[this.form.id ? 'edit' : 'add'].post(this.form);
					this.isSaveing = false;
					if (res.code == 1) {
						this.$emit('success', this.form, this.mode)
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				} else {
					return false;
				}
			})
		},
		//表单注入数据
		async setData(data) {
           this.form.id = data.id
           this.form.contract_id = data.contract_id
           this.form.time = data.time
           this.form.amount = data.amount
           this.form.driver = data.driver
           this.form.operater = data.operater
           this.form.remark = data.remark
        //    this.form.data = data.form.data
		},
        // 新增
        getId(contract_id) {
            this.form.contract_id = contract_id
        },
	}
}
</script>

<style lang="scss">
.el-input-group__append{
    padding: 0 8px;
}
</style>
